package io.jjz.config;

import com.alibaba.fastjson.JSON;
import io.leopard.javahost.JavaHost;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Properties;

@Configuration
public class EnvConfig {

    private static final Logger LOGGER = LoggerFactory.getLogger(EnvConfig.class);

    // 配置虚拟ip  CLUSTER_HOST={"izl77o32a1dk27z":"120.26.140.216"} 注意大小写
    @PostConstruct
    public void init() {
        String quorum = System.getenv("CLUSTER_HOST");
        //Assert.notNull(quorum, "zookeeper集群IP端口信息尚未配置");
        try {
            Properties hostAndIps = JSON.parseObject(quorum, Properties.class);
            JavaHost.updateVirtualDns(hostAndIps);
            LOGGER.info("集群机器名host映射配置完成");
        } catch (Exception e) {
            throw new RuntimeException("host配置错误" + quorum, e);
        }
    }

}
